package SV_LDAP;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchResult;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class Example {
    private static final String ATTRIBUTE_TYPE = "";

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException, NamingException {
            String name = "dc=example,dc=com";
            DirContext context = LDAPUtils.initializeContext();
            String filter = req.getParameter("filter");

            NamingEnumeration<SearchResult> namingEnumeration = context.search(name, filter, null);

            while (namingEnumeration.hasMore()) {
                SearchResult searchResult = namingEnumeration.next();
                Attribute attribute = searchResult.getAttributes().get("");
                if (ATTRIBUTE_TYPE.equals(attribute.getID())) {
                    resp.getOutputStream().println(attribute.get() + ";");
                }

            }
    }
}
